package com.heima.comment.controller;

import com.heima.comment.service.CommentRepayService;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author Lijx
 * @Date 2024-08-01 21:23
 */
@RestController
@RequestMapping("/api/v1/comment_repay")
@Slf4j
public class CommentRepayController {

    @Autowired
    private CommentRepayService commentRepayService;

    /**
     * 加载回复评论列表
     * @param params
     * @return
     */
    @PostMapping("/load")
    public ResponseResult getCommentRepayList(@RequestBody Map<String,Object> params){
        log.info("获取回复评论列表接口，入参={}",params);
        String commentId = (String)params.get("commentId");
        Object minDate = params.get("minDate");
        if (minDate == null || commentId == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_REQUIRE);
        }
        return commentRepayService.getCommentRepayList(commentId,minDate);
    }

    /**
     * 保存回复评论
     * @param params
     * @return
     */
    @PostMapping("/save")
    public ResponseResult saveCommentRepay(@RequestBody Map<String,String> params){
        log.info("保存回复评论接口，入参={}",params);
        String commentId = params.get("commentId");
        String content = params.get("content");
        if (content == null || commentId == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_REQUIRE);
        }
        return commentRepayService.saveCommentRepay(commentId,content);
    }

    /**
     * 回复评论点赞
     * @param params
     * @return
     */
    @PostMapping("/like")
    public ResponseResult commentRepayLike(@RequestBody Map<String,String> params){
        log.info("回复评论点赞接口，入参={}",params);
        String commentRepayId = params.get("commentRepayId");
        String operation = params.get("operation");
        if (operation == null || commentRepayId == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_REQUIRE);
        }
        return commentRepayService.commentRepayLike(commentRepayId,Integer.valueOf(operation));
    }
}
